"use strict";

// src/Startup/closeSidebarOnMobile.ts
exports.name = "close-sidebar-on-mobile";
exports.platforms = ["browser"];
exports.after = ["rootwidget"];
var isOnMobile = () => {
  if (typeof navigator !== "undefined") {
    if (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent)) {
      return true;
    }
    const mobileBreakpointWidth = $tw.wiki.getTiddler("$:/themes/tiddlywiki/vanilla/metrics/sidebarbreakpoint")?.fields?.text ?? "0px";
    if (window.innerWidth < Number(mobileBreakpointWidth.replace("px", ""))) {
      return true;
    }
  }
  return false;
};
var closeSidebar = () => {
  $tw.wiki.addTiddler({ title: "$:/state/sidebar", text: "no" });
  $tw.wiki.addTiddler({ title: "$:/state/notebook-sidebar", text: "no" });
};
var closeSidebarOnMobile = (event) => {
  if (isOnMobile()) {
    closeSidebar();
  }
  return event;
};
var setup = () => {
  $tw.hooks.addHook("th-opening-default-tiddlers-list", closeSidebarOnMobile);
  $tw.hooks.addHook("th-navigating", closeSidebarOnMobile);
  $tw.hooks.addHook("th-new-tiddler", closeSidebarOnMobile);
  $tw.hooks.addHook("th-open-command-palette", closeSidebarOnMobile);
  closeSidebarOnMobile();
};
exports.startup = setup;
